//
//  SISSLeftLabelRightButton.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/4/9.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSLeftLabelRightButton.h"

@interface SISSLeftLabelRightButton ()

/* leftLabel */
@property (weak, nonatomic) UILabel *leftLabel;
/* rightButton */
@property (weak, nonatomic) UIButton *rightButton;

@end
@implementation SISSLeftLabelRightButton

- (void)setLeftStr:(NSString *)leftStr {
    _leftStr = leftStr;
    self.leftLabel.text = leftStr ? leftStr : @" ";
}

- (void)setRightImage:(UIImage *)rightImage {
    _rightImage = rightImage;
    [self.rightButton setImage:rightImage forState:UIControlStateNormal];
}

- (void)rightButtonClickAction {
    if (self.rightButtonClickBlock) {
        self.rightButtonClickBlock();
    }
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    self.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UILabel *leftLabel = [UILabel yyr_labelWithText:@"title" fontSize:15 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:leftLabel];
    self.leftLabel = leftLabel;
    
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setImage:[UIImage imageNamed:@"?-anz"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightButton];
    self.rightButton = rightButton;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(1.5 * margin);
        make.bottom.equalTo(self).offset(-1.5 * margin);
    }];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftLabel.mas_right).offset(margin);
        make.centerY.equalTo(self.leftLabel);
    }];
}

@end
